//
//  UIBarButtonItem+YPKinit.m
//  YouPinKu
//
//  Created by 李昭宏 on 15/10/16.
//  Copyright © 2015年 李昭宏. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)

+ (instancetype)initWithRightImageName:(NSString *)imageName target:(id)target action:(SEL)action {
    UIButton * button = [[UIButton alloc]init];
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 24, 24);
    button.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -5);
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc]initWithCustomView:button];
}

+ (instancetype)initWithLeftImageName:(NSString *)imageName target:(id)target action:(SEL)action {
    UIButton * button = [[UIButton alloc]init];
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 25, 30);
    button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc]initWithCustomView:button];
}

@end
